<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

</head>
<style>
    .marsk {
    background-color: green;
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-wrap {
    border-radius: 10px;
    background-color: #fff;
    width: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

/* 提示框间距 */
.marsk .title, .marsk .footer, .marsk .body {
    margin: 20px 0
}

button {
    outline: none;
    border:0;
    width: 200px;
    height: 40px;
    background: blue;
    border-radius: 20px;
    display: block;
    color: #fff;
    cursor:pointer;
}

</style>
<body>
    <div id="app">
        <!-- 点击事件出发显示弹框 -->
        <button @click="showModal=true">打开模态框</button>
        <!-- 自定义事件，实现组件通信 -->
        <modal :visible="showModal" @on-confirm="confirm"></modal>
    </div>
    
</body>
</html>

<template id='modal'>
    <div class="marsk" v-if="visible" key="div">
        <div class="modal-wrap">
            <div class="title">
                提示
            </div>
            <div class="body">
                哎呦！你绿了
            </div>
            <div class="footer">
                <button @click="confirm">确定</button>
            </div>
        </div>
    </div>

</template>

<script>
        Vue.component("modal", {
        template: "#modal",
        props: {
            visible: {
                type: Boolean, 
                default() {
                    return false
                }
            }
        },
        methods: {
            confirm() {
                this.$emit("on-confirm")
            }
        }
    })
    const vm = new Vue({
        el: "#app",
        data: {
            showModal: false
        },
        methods: {
            confirm() {
                this.showModal = false
            }
        }
    })
</script>